<?php

class Admin_Form_Question extends Zend_Form
{
	private $_options;
	public function __construct($options) {
		$this->_options = $options;
		parent::__construct();
	}

    public function init()
    {
        $this->setName('Add/edit Question');
        
        $content_elem = new Zend_Form_Element_Textarea('content');
        $content_elem->setLabel('Content');
        $content_elem->setAttribs(array('rows' => 5, 'cols' => 63));
        $this->addElement($content_elem);
        $option_elem = new Zend_Form_Element_Textarea("note");
        $option_elem->setAttribs(array('rows' => 3, 'cols' => 63));
        $option_elem->setLabel("Note");
        $this->addElement($option_elem);
        $sub_form = new Zend_Form_SubForm();
        $options_add_elem = new Zend_Form_Element_Button('add');
        $options_add_elem->setLabel('+');
        $options_add_elem->setDecorators(array('ViewHelper'));
        $options_add_elem->setAttrib('onClick', 'add_option()');
        $sub_form->addElement($options_add_elem);
        $options_remove_elem = new Zend_Form_Element_Button('remove');
        $options_remove_elem->setLabel('-');
        $options_remove_elem->setDecorators(array('ViewHelper'));
        $options_remove_elem->setAttrib('onClick', 'remove_option()');
        $sub_form->addElement($options_remove_elem);
        for ($i = 1; $i <= $this->_options; $i++) {
        	$option_elem = new Zend_Form_Element_Textarea("o$i");
        	$option_elem->setLabel(MyQuiz_Utilities::numberToLetter($i) . ')');
        	$option_elem->setAttribs(array('rows' => 3, 'cols' => 53));
        	$option_elem->setBelongsTo('options');
        	$sub_form->addElement($option_elem);
        	
        	$option_note_elem = new Zend_Form_Element_Textarea("n$i");
        	$option_note_elem->setAttribs(array('rows' => 2, 'cols' => 40));
        	$option_note_elem->getDecorator('Label')->setOption('tag', null);
        	$option_note_elem->getDecorator('HtmlTag')->setOption('class', 'form_input-float_left');
        	$option_note_elem->setAttrib('placeholder', 'Note');
        	$option_note_elem->setBelongsTo("options");
        	$sub_form->addElement($option_note_elem);
        	
        	$option_check_elem = new Zend_Form_Element_Checkbox("a$i");
        	$option_check_elem->setLabel("Is answer");
        	//$option_check_elem_decorator = new MyQuiz_Form_Decorator_SimpleCheckBox();
        	//$option_check_elem_decorator->setOption('class', 'form_input-simplecheckbox');
        	//$option_check_elem->addDecorator($option_check_elem_decorator);
        	$option_check_elem->setBelongsTo("options");
        	$sub_form->addElement($option_check_elem);
        	
        	$option_clear_elem = new Zend_Form_Element_Hidden("c$i");
        	$option_clear_elem->setRequired(false);
        	$option_clear_elem->setIgnore(true);
        	$option_clear_elem->setBelongsTo('options');
        	$option_clear_elem->setDecorators(array(
			            array(
			                'HtmlTag', array(
			                    'tag'  => 'div',
			                    'id'   => "clears-c$i-element",
			                    'class' => 'clear'
			                )
			            )));
			$option_clear_elem->clearValidators();
			$sub_form->addElement($option_clear_elem);
        }
        $sub_form->setLegend('Options');
        
        $this->addSubForm($sub_form, 'options');
        $submit_elem = new Zend_Form_Element_Submit('submit');
        $submit_elem->setLabel('Submit');
        $this->addElement($submit_elem);
    }


}

